<?php
require('crawler.class.php');
require('config.php');
require('phpQuery/phpQuery/phpQuery.php');

$url = str_replace(' ', '%20', $_POST['startUrl']);


$filterUrl = cleanValue($_POST['filterUrl']);
$filterString = cleanValue($_POST['filterString']);

$filterDetail = cleanValue($_POST['filterDetail']);
$filterContentString = cleanValue($_POST['filterContentString']);

$limitUrl = intval($_POST['limitUrl']);

$removeDom = cleanValue($_POST['removeDom']);
$urlAdd = $_POST['urlAdd'];
$crawler = new Crawler($url, $limitUrl);
/*if($filterUrl == 'RSS'){
	$urls = $crawler->rssExtractor();
	if(!empty($urls)){
		foreach($urls as $feed){
			$links['links'][] = $feed['link'];
		}
		$detail = $crawler->getDetail($links['links'][0], $filterDetail, $filterContentString);
		$links['detail'] = $detail['content'];
	}
}
else{*/
	$links = $crawler->getLinks($filterUrl, $filterString, array(
		'detailType' => $filterDetail,
		'detailString' => $filterContentString,
		'removeDom' => $removeDom,
		'urlAdd' => $urlAdd,
		'demo' => true));
//}

die(json_encode(array('data' => $links['links'], 'detail' => $links['detail'])));

